import { GCellRenderer } from "../../../../../com/mui/controls/GCellRenderer";
import { ShopItemInfo } from "../../../resource/info/ShopItemInfo";
import { ItemData } from "../../../resource/info/ItemData";
import { ItemsUtil } from "../../shortcuts/item/ItemsUtil";
import { Language } from "../../../../../extend/language/Language";
import { Cache } from "../../../cache/Cache";
import { ObjCreate } from "../../common/ObjCreate";
import { ImagesConst } from "../../../resource/ImagesConst";
import { BaseItem } from "../../common/BaseItem";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { EffectManager } from "../../../manager/EffectManager";
import { BuyAlert } from "../../pet/BuyAlert";
import { GTextFiled } from "../../../../../com/mui/controls/GTextFiled";
import { GButton } from "../../../../../com/mui/controls/GButton";
import { LineBox } from "../../guide/LineBox";
type int = number;
//class ShopMeritCellRenderer
    
    export  class ShopMeritCellRenderer extends GCellRenderer
    {
        constructor()
        {
            super();
            this.init();
            return;
        }

        public /* override */ set data(arg1: Object)
        {
            super.data = arg1;
            this._shopItemInfo = arg1 as ShopItemInfo;
            if (this._shopItemInfo) 
            {
                this._itemData = new ItemData(this._shopItemInfo.itemInfo.item.code);
                this._nameTxt.htmlText = ItemsUtil.getItemName(this._itemData);
                this._meritTxt.text = Language.getString(53089) + this._shopItemInfo.tshopSell.price.toString();
                this._itemLevel = this._itemData.itemInfo.item.itemLevel;
                this._price = this._shopItemInfo.tshopSell.price;
            }
            this._baseItem.itemData = this._itemData;
            this._medalCode = Cache.instance.role.medalCode;
            if (this._medalCode > 0) 
            {
                this._medalItemData = new ItemData(this._medalCode);
                if (this._medalItemData) 
                {
                    this._medalLevel = this._medalItemData.itemInfo.item.itemLevel;
                }
            }
            if (this._medalLevel > 0 && this._itemLevel == this._medalLevel) 
            {
                this.showLineBox(true);
            }
            else 
            {
                this.showLineBox(false);
            }
            if (Cache.instance.role.money.merit >= this._price) 
            {
                this.updateByEnable(true);
            }
            else 
            {
                this.updateByEnable(false);
            }
            return;
        }

        /* internal  */init(): void
        {
            ObjCreate.createBg(0, 0, 180, 75, this, ImagesConst.DisabledBg);
            ObjCreate.createBg(10, 5, 60, 65, this, ImagesConst.PackItemBg);
            this._baseItem = new BaseItem();
            this._baseItem.setSize(54, 59);
            this._baseItem.move(12, 7);
            this.addChild(this._baseItem);
            this._nameTxt = ObjCreate.createGTextField("", 80, 5, 100, 20, this);
            this._nameTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._meritTxt = ObjCreate.createGTextField("", 80, 25, 100, 20, this, GlobalStyle.textFormat6);
            this._meritTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._dressBtn = ObjCreate.createGButton(Language.getString(54726), 80, 48, 50, 24, this);
            this._dressBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onDressBtnClickHandler);
            this._dressBtn.drawNow();
            return;
        }

        /* internal  */updateByEnable(arg1: Boolean): void
        {
            if (arg1) 
            {
                this._nameTxt.htmlText = ItemsUtil.getItemName(this._itemData);
                this._meritTxt.textColor = 15788607;
                this._dressBtn.enabled = true;
            }
            else 
            {
                this._nameTxt.textColor = 8158332;
                this._meritTxt.textColor = 8158332;
                this._dressBtn.enabled = false;
            }
            this._dressBtn.drawNow();
            return;
        }

        /* internal  */showLineBox(arg1: Boolean): void
        {
            if (arg1) 
            {
                if (!this._lineBox) 
                {
                    this._lineBox = EffectManager.getLineBox(180, 75, [65280]);
                    this._lineBox.x = 0;
                    this._lineBox.y = 0;
                }
                if (!this.contains(this._lineBox)) 
                {
                    this.addChild(this._lineBox);
                }
            }
            else if (this._lineBox && this.contains(this._lineBox)) 
            {
                this.removeChild(this._lineBox);
                EffectManager.disposeLineBox(this._lineBox);
                this._lineBox = null;
            }
            return;
        }

        /* internal  */onDressBtnClickHandler(arg1: Object /* flash.events.Event */): void
        {
            if (this._shopItemInfo) 
            {
                BuyAlert.showByShopItemInfo(this._shopItemInfo);
            }
            return;
        }

        /* internal */ /* var */_baseItem: BaseItem;

        /* internal */ /* var */_nameTxt: GTextFiled;

        /* internal */ /* var */_meritTxt: GTextFiled;

        /* internal */ /* var */_dressBtn: GButton;

        /* internal */ /* var */_lineBox: LineBox;

        /* internal */ /* var */_shopItemInfo: ShopItemInfo;

        /* internal */ /* var */_medalCode: int;

        /* internal */ /* var */_medalItemData: ItemData;

        /* internal */ /* var */_medalLevel: int;

        /* internal */ /* var */_itemData: ItemData;

        /* internal */ /* var */_itemLevel: int;

        /* internal */ /* var */_price: int;

        /* internal */ /* var */_isEnable: Boolean;
    }
